package com.atguigu.flinksql;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

public class Flink08_Time_Processing_SQL {
    public static void main(String[] args) {
        Configuration configuration = new Configuration();
        configuration.setInteger("rest.port",10000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(configuration);
        env.setParallelism(2);

        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);

        //创建建表sql
        tEnv.executeSql("create table sensor(" +
                " id string, " +
                " ts bigint, " +
                " vc int, " +
                " pt as proctime() " +
                ")with(" +
                " 'connector' = 'filesystem', " +
                "  'path' = 'input/sensor.txt', " +
                "  'format' = 'csv'  )");

        //从表中查询
        //查询元数据
        tEnv.from("sensor").printSchema();

        tEnv.sqlQuery(" select * from sensor ").execute().print();
    }
}
